using System;
using System.Text;
using Microsoft.Practices.RecipeFramework;
using Microsoft.Practices.ComponentModel;
using EnvDTE;

namespace SPALM.SharePointSoftwareFactory.Library.ValueProviders
{
    /// <summary>
    /// Provides the type of template which is used in the project, either VSEWSS-Format or HIVE Format
    /// </summary>
    [ServiceDependency(typeof(DTE))]
    public class IsHIVETemplateTypeValueProvider : ValueProvider
    {
        public override bool OnBeginRecipe(object currentValue, out object newValue)
        {
            DTE service = (DTE)this.GetService(typeof(DTE));
            Project project = Helpers.GetSelectedProject(service);

            if (project == null)
            {
              //find first project
              foreach (Project p in Helpers.GetAllProjects(service))
              {
                if (Helpers2.IsVSTemplate(service, p))
                {
                  newValue = false;
                  return true;
                }
              }
            }

            if (project == null)
            {
              //if not project is there and no project is VSTemplate, then it must be HIVE
              newValue = true;
              return true;
            }

            if(Helpers2.IsVSTemplate(service, project))
            {
              newValue = false;
              return true;
            }

          //if not VS Template then only HIVE template is assumed
            newValue = true;
            return true;
        }        
    }
}
